package com.qdlc.p2p.manage.action.additional;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.ExperienceBorrowService;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.common.util.MessageUtil;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dto.ExperienceBorrow;
import com.qdlc.p2p.dal.model.ExperienceBorrowModel;

/**
 * 体验标管理Aciton
 * @author xxx
 * @version 2.0
 * @date 2015年4月23日 下午5:52:19
 */
public class ManageExperienceBorrowAction extends BaseAction<ExperienceBorrowModel> implements ModelDriven<ExperienceBorrowModel> {
	
	@Resource
	private ExperienceBorrowService experienceBorrowService;
	
	/**
	 * 体验标实体对象
	 */
	private ExperienceBorrow experienceBorrow;
	
	private Map<String, Object> data;
	
	@Action("/modules/additional/experienceBorrow/manage")
	public String manage(){
		return "manage";
	}
	
	/**
	 * 获取列表信息
	 * @throws IOException
	 */
	@Action("/modules/additional/experienceBorrow/list")
	public void list() throws IOException{
		data = new HashMap<String, Object>();
		PageDataList<ExperienceBorrowModel> pagaDataList = experienceBorrowService.findByModel(model);
		int total = pagaDataList.getPage().getTotal();
		data.put("total", total);
		data.put("rows", pagaDataList.getList());
		printJson(getStringOfJpaObj(data));
	}

	/**
	 * 添加
	 * @return
	 */
	@Action("/modules/additional/experienceBorrow/append")
	public String append(){
		return "append";
	}
	
	/**
	 * 添加
	 * @throws Exception
	 */
	@Action("/modules/additional/experienceBorrow/doAppend")
	public void doAppend() throws Exception {
		data = new HashMap<String, Object>();
		model.validModelData();
		ExperienceBorrow experienceBorrow = model.prototype();
		experienceBorrowService.save(experienceBorrow);
		data.put("result", "true");
		data.put("msg", MessageUtil.getMessage("MS102001001"));
		printJson(getStringOfJpaObj(data));
	}
	
	/**
	 * 修改
	 * @return
	 */
	@Action("/modules/additional/experienceBorrow/modify")
	public String modify() {
		ExperienceBorrow experienceBorrow = experienceBorrowService.findById(model.getId());
		request.setAttribute("experienceBorrow", experienceBorrow);
		return "modify";
	}
	
	/**
	 * 修改
	 * @return
	 */
	@Action("/modules/additional/experienceBorrow/doModify")
	public void doModify() throws Exception {
		data = new HashMap<String, Object>();
		model.validModelData();
		ExperienceBorrow experienceBorrow = model.prototype();
		experienceBorrowService.update(experienceBorrow);
		data.put("result", "true");
		data.put("msg", MessageUtil.getMessage("MS102002001"));
		printJson(getStringOfJpaObj(data));
	}

	public ExperienceBorrow getExperienceBorrow() {
		return experienceBorrow;
	}

	public void setExperienceBorrow(ExperienceBorrow experienceBorrow) {
		this.experienceBorrow = experienceBorrow;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}
	
}
